//
//  QZDJnet.m
//  QZDJcharge
//
//  Created by Rain on 16/6/22.
//  Copyright © 2016年 Rain. All rights reserved.
//

#import "QZDJnet.h"
#import <AFHTTPSessionManager.h>

__strong static AFHTTPSessionManager *AFHTTPMgr;
__strong static QZDJnet *NetInstance=nil;

@implementation QZDJnet

+(QZDJnet*)getInstance
{
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken,^{
        
        NetInstance=[[QZDJnet alloc]init];
        
        //是AFHTTPOerrationManager的配置
        AFHTTPMgr=[AFHTTPSessionManager manager];
        
        //申明请求的数据是json类型
        //AFHTTPMgr.requestSerializer=[AFJSONRequestSerializer serializer];
        
        //申明返回的结果是json类型
        //AFHTTPMgr.responseSerializer=[AFJSONResponseSerializer serializer];
        AFHTTPMgr.responseSerializer=[AFHTTPResponseSerializer serializer];
        
        //如果报接受类型不一致请替换一致text/xml或别的
        //AFHTTPMgr.responseSerializer.acceptableContentTypes= [NSSet setWithObject:@"text/xml"];
        
        //设置超时时间
        AFHTTPMgr.requestSerializer.timeoutInterval=5;
        
    });
    
    return NetInstance;
}

-(void)getChargeMoneyUseOid:(NSString *)oid andChargeMon:(NSString *)chargeMon
{
    //接口地址
    NSString *url=[NSString stringWithFormat:@"http://192.168.1.189:8888/property/app_and/appQueryActualChargeMon"];
    
    //参数
    NSDictionary *parameters=[NSDictionary dictionaryWithObjectsAndKeys:oid, @"oid", chargeMon, @"chargeMon",nil];
    
    //发送请求
    [AFHTTPMgr POST:url parameters:parameters constructingBodyWithBlock:^(id  _Nonnull formData) {
        //拼接data到请求体
    } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        [self.delegate getChargeMoneyInfoSuccessFeedback:responseObject];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        [self.delegate getChargeMoneyInfoFailFeedback:error];
        
    }];
}

@end
